/*搜索函数*/
function searchList(pageNum) {
    var params = {
        "curPage": pageNum,
        "rows": 10,
        "skuCode": $(".sku-code").val(),
    }
    web.doAjax(root.dockingplatform.getSkuSettleInfoList, 'post',params, function (data) {
        if(data.errorCode == 0){
            $('.M-box3').pagination({
                pageCount:data.data?data.data.totalPage:0,
                current:pageNum,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                    comPageNum = api.getCurrent();
                    searchList(api.getCurrent());
                }
            });
            if(data.data){
                renderList(data.data.result);
            }else {
                var listHtml = '<tr class="text-c"><td colspan="8">无数据</td></tr>';
                $("#datatable .table-tbody").html(listHtml);
            }
        }else {

        }
    },1);
}
function renderList(data) {
    console.log(data)
    var listHtml = "";
    data.forEach((item,index) => {
        listHtml += '<tr class="text-c">\n' +
            '                    <td title="'+item.skuCode+'">'+item.skuCode+'</td>\n' +
            '                    <td title="'+item.skuName+'">'+item.skuName+'</td>\n' +
            '                    <td title="'+item.saleUnit+'">'+item.saleUnit+'</td>\n' +
            '                    <td title="'+item.settleUnit+'">'+item.settleUnit+'</td>\n' +
            '                    <td title="'+item.settleRate+'">'+item.settleRate+'</td>\n' +
            '                    <td title="'+item.operateUsername+'">'+item.operateUsername+'</td>\n' +
            '                    <td title="'+item.createdTime+'">'+item.createdTime+'</td>\n' +
            '                    <td title="'+item.updatedTime+'">'+item.updatedTime+'</td>\n' +
            '                </tr>';
    });
    $("#datatable .table-tbody").html(listHtml);
}
/*下载Excel模板*/
function downloadExcelTemplateFn() {
    window.location.href = root.dockingplatform.downloadSkuSettleInfoExcelTemplate;
}
var formData = new FormData();
/*导入转化率*/
function uploadConversionRateFn() {
    formData.delete("file")
    var fileUpEl = document.getElementById('conversionRateFile') ;
    fileUpEl.outerHTML=fileUpEl.outerHTML;
    $("#conversionRateFile").trigger('click');
}
function putDataToPage(e,elId) {
    var limitSize = 5*1024*1024;
    for (var i = 0; i < e.target.files.length; i++) {
        var file = e.target.files.item(i);
        if (!(/excel*$/i.test(file.type))) {
            $.Huimodalalert('非excel格式',2000);
            return; //不是图片 就跳出这一次循环
        }
        /*if(file.size>limitSize){
            $.Huimodalalert('请上传5M以内的图片',2000);
            return;
        }*/
        //实例化FileReader API
        var freader = new FileReader();
        freader.readAsDataURL(file);
        freader.onload = function (e) {
            // $("#myImg").attr("src", e.target.result);
        }
    }
    uploadImg(elId);
}
function uploadImg(elId){
    formData.set('file', $("#conversionRateFile")[0].files[0]);
    $.ajax({
        url: root.dockingplatform.importSkuSettleInfoByExcel+"?operateUserName="+JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
        cache: false, //禁用缓存
        type: "POST",
        processData : false,
        // 告诉jQuery不要去设置Content-Type请求头
        contentType : false,
        data: formData,
        success: function (data) {
            if(data.errorCode == 0){
                $.Huimodalalert('导入成功',2000);
                searchList(1);
            }else {
                $.Huimodalalert(data.msg,2000);
            }
        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    })
}
/*失败信息导出*/
function exportFailInfoFn() {

}